package com.yzt.message.widget.chatinput.widget;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.yzt.message.R;
import com.yzt.plugin_imageloader.ImageLoadUtil;
import com.yzt.zhuju.richtext.entity.EmojiFatherBean;

import java.util.ArrayList;
import java.util.List;

/**
 * author : Irene
 * e-mail : 821970751@qq.com
 * date   : 2020/5/19 17:31
 * desc   :
 */
public class EmojiDialogAdapter extends RecyclerView.Adapter<EmojiDialogAdapter.ItemViewHolder> {

    private Activity activity;
    private List<EmojiFatherBean> list;
    private OnClickEmojiSelectListener listener;

    public EmojiDialogAdapter(Activity activity) {
        this.activity = activity;
        this.list = new ArrayList<>();
    }

    public void setOnClickEmojiSelectListener(OnClickEmojiSelectListener listener) {
        this.listener = listener;
    }

    public void initData(List<EmojiFatherBean> list) {
        this.list.clear();
        this.list.addAll(list);
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public ItemViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        return new ItemViewHolder(LayoutInflater.from(activity).inflate(R.layout.item_emoji_select, viewGroup, false));
    }

    @Override
    public void onBindViewHolder(@NonNull ItemViewHolder itemViewHolder, @SuppressLint("RecyclerView") final int position) {
        EmojiFatherBean emojiNewBean = list.get(position);
        // itemViewHolder.mSelectLayout.setBackgroundColor(ContextCompat.getColor(activity, emojiNewBean.isSelect() ? R.color.select_color : R.color.white));
//        if (emojiNewBean.getDrawableId() > 0) {
//            itemViewHolder.mIconSelect.setImageResource(emojiNewBean.getDrawableId());
//        } else
//        ImageLoadUtil.loadIv(itemViewHolder.mIconSelect.getContext(), emojiNewBean.resId, itemViewHolder.mIconSelect);
//        itemViewHolder.mSelectLayout.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                if (listener != null) {
//                    listener.selectIcon(position);
//                }
//            }
//        });
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    class ItemViewHolder extends RecyclerView.ViewHolder {
        private LinearLayout mSelectLayout;
        private ImageView mIconSelect;

        public ItemViewHolder(@NonNull View itemView) {
            super(itemView);
            mSelectLayout = itemView.findViewById(R.id.select_layout);
            mIconSelect = itemView.findViewById(R.id.icon_emoji);
        }
    }

    public interface OnClickEmojiSelectListener {
        void selectIcon(int position);
    }
}
